1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
lutik1710 [3]
3 years ago
9

The template code provided is intended to check whether an integer entered by the user is outside of the range 20-29 (inclusive)

. If it is outside of this range the program should print a warning and change the number to 25. However, when using De Morgan's law to simplify this code, the programmer has made some mistakes. Can you correct the errors so the code functions as intended? code: Scanner scan = new Scanner(System.In); System.Out.Println("Enter a number in the twenties"); int num = scan.NextInt(); if(num < 20 && num > 30){ System.Out.Println("That's not in the twenties!"); num = 25; } System.Out.Println("Your number is " + num);
Computers and Technology
1 answer:
irakobra [83]3 years ago
8 0

Answer:

Change if(num < 20 && num > 30)

to

if(num < 20 || num > 30)

Explanation:

The code has lots of errors most of which are as a result of case sensitivity of java programming language

The following errors were corrected.

All System.Out.Println were changed to System.out.println

scan.NextInt() was changed to scan.nextInt()

Now to the actual correction that needs to be made;

The programmer's error was in using the conditional statement.

The programmer used if(num < 20 && num > 30) as its condition which means that if num is less tha 20 and at the same time greater than 30

This is impossible because no number is greater than 30 and less than 20 at the same time.

So, the correction made was to change the && (and) to || (or) which means that numbers greater than 30 or less than 20.

<em></em>

<em>This corrects the programmer's mistake</em>

<em>See attachment for complete code</em>

Download txt
You might be interested in
Which of the following is a safe work practice to protect you from electrocution hazards?
Flura [38]
What are the answer choices?
7 0
3 years ago
Which of the following best describes compounds.
Lemur [1.5K]
A. They can only be separate chemically
4 0
3 years ago
Given the following program: public class MysteryNumbers { public static void main(String[] args) { String one = "two"; String t
enyata [817]

Answer:

Check the explanation

Explanation:

/*Given the following program:

public class MysteryNumbers {

   public static void main(String[] args) {

       String one = "two";

       String two = "three";

       String three = "1";

       int number = 20;

​

       sentence(one, two, 3);

       sentence(two, three, 14);

       sentence(three, three, number + 1);

       sentence(three, two, 1);

       sentence("eight", three, number / 2);

   }

​

   public static void sentence(String three, String one, int number) {

       System.out.println(one + " times " + three + " = " + (number * 2));

   }

}*/

Write the output of each of the following calls.

sentence(one, two, 3);     three times two = 6

sentence(two, three, 14); 1 times three = 28

sentence(three, three, number + 1); 1 times 1 = 42

sentence(three, two, 1);   three times 1 = 2

sentence("eight", three, number / 2); 1 times eight = 20

7 0
3 years ago
Write a class named Add that has the following data members, constructor, and methods:
taurus [48]

Answer:

A class is like a blueprint of object.

Explanation:

A class defines the kinds of data and the functionality their objects will have.

A class enables you to create your own custom types by grouping together variables of other types, methods and events.

In C#, we can create a class  using the class keyword.

Here's a sample program:

using System;

namespace ConsoleApplication

{

   public class Test

   {

       public static void Main()

       {

           Add a1 = new Add(70, 50);

           a1.AddNumbers();                    

           Console.ReadLine();

       }      

   }

     class Add

   {

       private int row;

       private int column;

       public Add(int r, int c)

       {

           row = r;

           column = c;

       }

       public void AddNumbers()

       {

           Console.WriteLine(row+column);

       }

   }

}

output: 120

Explanation of the program:

I have created a class named Add. Within a class, row and column are two fields and AddNumbers() is a method. We also have constructor to initialize row and column.

In main method, If I need to invoke members of the class, I must create  an instance of the class. We can create any number of instances using the single class.IN our program, a1 is the reference variable using which we can invoke members of the class. I invoked function in the class and passed arguments to the constructor while creating an instance.

Those values are assigned to method variables and it operated the addition. Thus the output is 120.

7 0
3 years ago
What is your definition of Green/Eco Driving?
Masja [62]
Using/driving with an electric car or using car that is ecologically friendly (less pollution) Ex.Bio Fuel
8 0
3 years ago
Other questions:
  • The common programming structure that implements "conditional statements" is called an____ statement.
    8·1 answer
  • How do i move a file in python3
    10·1 answer
  • Which of the following is the answer?
    5·1 answer
  • What are scientists going to explore next on Kepler-186f? A) evidence of the existence of life B) types of plant life that exist
    8·2 answers
  • When entering a function or formula in a cell, which is the first character
    15·1 answer
  • WIN
    9·2 answers
  • Which of the following is an advantage of text HTML editors over plain text editors?
    5·2 answers
  • Why When I change my pfp It be blurry and it be ugly- if you know what I mean :c
    15·2 answers
  • Select the best answer from the drop-down menu.
    14·2 answers
  • an existing technology that would allow users to transfer images from the camera to the computer without connecting them
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!