Wednesday, March 18, 2020

WEEK 7 ASSIGNMENT SOLUTION

GUYS I KNOW I WAS SUPER INCONSISTENT AND LATE IN UPLOADING THE SOLUTIONS BUT I WAS HAVING A BUSY TIME IN PAST FEW WEEKS(COLLEGE WORK ) , I AM NOT GIVING ANY EXCUSES BUT JUST LETTING YOU ALL GUYS KNOW WHAT WAS THE REASON DUE TO WHICH I AM UPLOADING VIDEOS SO LATE. AND THANKS FOR WATCHING MY STUFF. 

QUESTION 1:

import java.util.*;
public class Question1{
        public static void main (String[] args){

//Write the appropriate code to read the 3 integer values and find their sum.
 int a,b=0,sum=0;
          Scanner i = new Scanner(System.in);
          for(a=0; a<3; a++)
          {
            b=i.nextInt();
            sum=sum+b;
          }

QUESTION 2:


try{InputStreamReader r=new InputStreamReader(System.in); 
   BufferedReader br=new BufferedReader(r); 
   String number=br.readLine(); 
   int x = Integer.parseInt(number);
   System.out.print(x*x);
   }
catch(Exception e){
  System.out.print("Please enter valid data");
}

QUESTION 3:


// Complete the code to get specific indexed byte value and its corresponding char value.
String str=new String(barr,n,1);
System.out.println(barr[n]);
System.out.print(str);
}

QUESTION 4:


//Write your code here to count the number of vowels in the string "s1"
for(int i=0;i<s1.length();i++){
  char s=s1.charAt(i);
  if(s=='a'||s=='A'||s=='e'||s=='E'||s=='i'||s=='I'||s=='o'||s=='O'||s=='u'|| s=='U')
  {
    c=c+1;
  }
}

QUESTION 5:


//Replace the char in string "s1" with the char 'a' at index "n"  and print the modified string
byte[] barr=s1.getBytes();
byte b1=(byte) c;
barr[n]=b1;
System.out.print(new String(barr));
}

0 Comments:

Post a Comment