Question

6. From the following flow-chart, write the java code. false a<100 print Done true print Bad a++ 7. Given an array int[] myar
0 0
Add a comment Improve this question Transcribed image text
Answer #1

ans 6:

1 import java.util.*; 2 public class Main 3- { public static void main(String[] args) { Scanner sc=new Scanner(System.in); Sy

output:

Enter value of a:95 Bad Bad Bad Bad Bad Done ... Program finished with exit code o Press ENTER to exit console.

code:

import java.util.*;
public class Main
{
   public static void main(String[] args) {
       Scanner sc=new Scanner(System.in);
       System.out.print("Enter value of a:");
       int a=sc.nextInt(); /*here we take input of af a*/
       while(a<100) /*we do untill a<100*/
       {
       System.out.println("Bad"); /*if condition true than we print this*/
       a++;
       }
       System.out.println("Done"); /*when it get false than we print this*/
      
   }
}

ans 7:

Trace table of program myarray[i] 1= 38 1=4 9 1=5 1=6 5 s=s+myarray[i] 10+8=18 18+9=27 27+7=34 34+5=39 ► In the above trace t

final value of s = 39

ans 8:

ovou ĐWN import java.util.*; 2 public class Main 3- { public static void main(String[] args) { ArrayList<String> mywords = ne

output:

... Program finished with exit code 0 Press ENTER to exit console.

here we get blank output because only one data is in mywords.so,k=1 so 2<1 getting false......

Add a comment
Know the answer?
Add Answer to:
6. From the following flow-chart, write the java code. false a<100 print Done true print Bad...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In Java programming language Please write code for the 6 methods below: Assume that Student class...

    In Java programming language Please write code for the 6 methods below: Assume that Student class has name, age, gpa, and major, constructor to initialize all data, method toString() to return string reresentation of student objects, getter methods to get age, major, and gpa, setter method to set age to given input, and method isHonors that returns boolean value true for honors students and false otherwise. 1) Write a method that accepts an array of student objects, and n, the...

  • use java and write in text a. Rewrite the following code segment using if statements. Assume...

    use java and write in text a. Rewrite the following code segment using if statements. Assume that grade has been declared as of type char. char grade= 'B';; switch (grade) { case 'A': System.out.println("Excellent"); break case 'B': System.out.println("Good"); default: System.out.println("you can do better”); } - b. write Java code that inputs an integer and prints each of its digit followed by ** e.gif the integer is 1234 then it should print 1**2**3**4 e.g. if the integer is 85 then it...

  • Please write where its written write your code here!! please use java for the code! please...

    Please write where its written write your code here!! please use java for the code! please use the given code and I will rate thanks Magic index in an array a[1..n] is defined to be an index such that a[ i ] = i. Given an array of integers, write a recursive method to find the first magic index from left to right. If one exists in the given array, return the index number i, otherwise return -1. Here are...

  • *Java* Hi. I need some help with creating generic methods in Java. Write a program GenMethods...

    *Java* Hi. I need some help with creating generic methods in Java. Write a program GenMethods that has the following generic methods: (1) Write the following method that returns a new ArrayList. The new list contains the nonduplicate (i.e., distinct) elements from the original list. public static ArrayList removeDuplicates(ArrayList list) (2) Write the following method that shuffles an ArrayList. It should do this specifically by swapping two indexes determined by the use of the random class (use Random rand =...

  • Assignment 06 – Ten Array Methods You must work in alone on this assignment. Do not...

    Assignment 06 – Ten Array Methods You must work in alone on this assignment. Do not use any Java language features we have not cover so far in this course. Assignment Objectives After completing this assignment the student should be able to:  Declare and instantiate arrays  Access array elements by index  Use loops and decisions to manipulate arrays and array elements  Write methods that manipulate arrays  Write methods that take array arguments  Write methods...

  • 6. (4 points) The following code for insertion sort has been modified to print out the...

    6. (4 points) The following code for insertion sort has been modified to print out the sorted component of the array during the sort. What will be the output of running the main method of the following code? Try to trace by hand and then verify by executing the code public class Insertion ( public static void sort (String[] a) f int n- a.length; for (int i-1; i < n; i++) f for (int j i; j 0; j--) if...

  • this is a while array mystery from java. please help me to write the code for...

    this is a while array mystery from java. please help me to write the code for this question to run it on eclipse !! I want the full code to run this program !! Consider the following method: public static void arrayMystery (int[] a) { for (int i = a. length - 1; i >= 1; i--) { if (a[i] > ali - 1] + 10) { ali - 1] = a[i - 1] + 5; Indicate in the right-hand...

  • 1.The following statement gets an element from position 4 in an array named myArray: x =...

    1.The following statement gets an element from position 4 in an array named myArray: x = myArray[4]; What is the equivalent operation using an array list named list.? A x = list.get(); B x = list.get(4); C x = list.get[4]; D x = list[4]; 2.Consider the following code snippet: ArrayList<Integer> num1 = new ArrayList<Integer>(); int data; Scanner in = new Scanner(System.in); for (int i = 0; i < 5; i++) { data = in.nextInt(); num1.add(data); if (data == 0 &&...

  • Java Programming. Write your own source code with comments. (Print distinct numbers) Write a program that...

    Java Programming. Write your own source code with comments. (Print distinct numbers) Write a program that reads in ten numbers and displays the number of distinct numbers and the distinct numbers separated by exactly one space (i.e., if a number appears multiple times, it is displayed only once). (Hint: Read a number and store it to an array if it is new. If the number is already in the array, ignore it.) After the input, the array contains the distinct...

  • write the following code in java thank you and if you can, could you please write...

    write the following code in java thank you and if you can, could you please write the code in replit and sent me a link to it replit is basically like a online compiler and you can write java code on it thank you The first part is to implement one of the questions from your examination. /* A Range objects represents an integer range, such as 1-10 or 50701-50799. The lower and upper bounds of a Range are given...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT