RecyclerView notifyItemRangeChanged doesn’t show new data

I am running into an issue with the RecyclerView#Adapter regarding notifyItemRangeChanged. It seems that if the Adapter thinks it has a size of 0 from the last call to getItemCount, and then I call Adapter#notifyItemRangeChanged(0, 1), the Adapter will simply ignore the call (it doesn’t result in the new item being inserted, for example).

Is this the expected behavior?

RecyclerView notifyItemRangeChanged doesn’t show new data

Why are my forked processes not returning the value I want to get back?

I currently have to write a program which creates as much forked processes as the user wants, then wait for all of them to complete and let them return a random number between 1 and 6.

This is my code so far:

#include <time.h>
#include <stdlib.h>
#include <stdio.h>

int main(){

  int n,i;
  int *returnvalue, value;
  int pid;
  int waitingID;

  returnvalue = &value;

  printf("How many processes to start?\n");
  scanf("%d",&n);

  for(i=0; i < n; i++){
    pid = fork();
    if(pid==0){
      printf("I am %d, from iteration %d\n",getpid(), i);
    }
    else if(pid > 0){
      waitingID = waitpid(pid, returnvalue, 0);
      printf("Return-value of %d is: %d\n", waitingID, *returnvalue);
      break;
    }
    else{
      printf("A problem occured.");
    }
  }

  srand(time(NULL));
  exit((rand()%6)+1);

  return 0;
}

read more

Java – If statement logic error

The sequence of events should be:

1) I enter two.
2) I am prompted to choose a name.
3) I choose either Washington/ Franklin/ Hamilton.
4) I’m asked which denomination does this name appear on.
5) I give the answer.

However, when I enter Washington for part three – I am told that is an invalid number. I cannot see why this would be.

public static void main(String[] args) {
    // TODO code application logic here
    System.out.println("Type 1 to enter a denomination, 2 to enter a last name");
    Scanner in = new Scanner(System.in);
    int x = in.nextInt();

    if(x==1){
        System.out.println("Choose a denomination");
        int y = in.nextInt();
        in.nextLine();
        if(y==1){
            System.out.println("Which person appears on the 1 bill?");
            String answer = in.nextLine();
            if(answer.equals("Washington")){
                System.out.println("That is correct");
            }
            else{
                System.out.println("That is incorrect");
            }
        }


        else if(y==10){
            System.out.println("Which person appears on the 10 bill?");
            String answer = in.nextLine();
            if(answer.equals("Hamilton")){
                System.out.println("That is correct");
            }
            else{
                System.out.println("That is incorrect");
            }
        }
        else if(y==100){
            System.out.println("Which person appears on the 100 bill?");
            String answer = in.nextLine();
            if(answer.equals("Franklin")){
                System.out.println("That is correct");
            }
            else{
                System.out.println("That is incorrect");
            }
        }
        else{
            System.out.println("That is an invalid number.");
        }
    }
    else if(x==2){
       System.out.println("Choose a name");
        String y = in.nextLine();
        in.nextLine();
        if(y.equals("Washington")){
            System.out.println("Which denomination does this name appear on?");
            int answer = in.nextInt();
            if(answer==1){
                System.out.println("That is correct");
            }
            else{
                System.out.println("That is incorrect");
            }
        }


        else if(y.equals("Hamilton")){
            System.out.println("Which denomination does this name appear on");
            int answer = in.nextInt();
            if(answer==10){
                System.out.println("That is correct");
            }
            else{
                System.out.println("That is incorrect");
            }
        }
        else if(y.equals("Franklin")){
            System.out.println("Which denomination does this name appear on");
            int answer = in.nextInt();
            if(answer==100){
                System.out.println("That is correct");
            }
            else{
                System.out.println("That is incorrect");
            }
        }
        else{
            System.out.println("That is an invalid number.");
        }
    } 
}

read more

validating a word in multi-line paragraph

I am using bash script to validate the output of a c++ code file. The output is multi-line containing questions asked by the code and their answers given by users. I am just concerned about the last keyword of the file(“result-Ball”). The multi line text can have statements containing ‘.’, ‘?’ or ‘!’ and any alphabets or special characters like ‘-‘. The script supplies input as a user using ‘yes’ command and I am transferring all the text to a different file for validation. I looking for a general keyword matching regular expression to ‘grep’ on my multi-line text.

read more