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
Ostrovityanka [42]
2 years ago
8

This program needs to be written in Java. Along with NO For/while loops, and no methods.

Computers and Technology
1 answer:
Umnica [9.8K]2 years ago
6 0
The only way without a while loop and no method I can think of is use switch with every possible variation of the four digit binary which is 15.

Here is the starter code:

import java.util.Scanner;
public class MyClass {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int digit = sc.nextInt();
switch(digit) {
case 0000:
System.out.println("0");
break;
case 0001:
System.out.println("1");
break;
case 0010:
System.out.println("2");
break;
case 0011:
System.out.println("3");
break;
case 0100:
System.out.println("4");
break;

… (fill in other cases)


}
}
}

Use this link: https://www.electronics-tutorials.ws/binary/bin_3.html

There might be a better way, but without loops or methods this is all I got.
You might be interested in
Write the contributions of dr herman hollerith​
Ad libitum [116K]

He invented the tabulating machine. In 1890 U.S

5 0
3 years ago
// This pseudocode segment is intended to compute and display
Finger [1]

The pseudocode to calculate the average of the test scores until the user enters a negative input serves as a prototype of the actual program

<h3>The errors in the pseudocode</h3>

The errors in the pseudocode include:

  • Inclusion of unusable segments
  • Incorrect variables
  • Incorrect loops

<h3>The correct pseudocode</h3>

The correct pseudocode where all errors are corrected and the unusable segments are removed is as follows:

start

Declarations

     num test1

     num test2

     num test3

     num average

output "Enter score for test 1 or a negative number to quit"

input test1

while test1 >= 0

     output "Enter score for test 2"

     input test2

     output "Enter score for test 3"

     input test3

     average = (test1 + test2 + test3) / 3

     output "Average is ", average

     output "Enter score for test 1 or a negative number to quit"

     input test1

endwhile

output "End of program"

stop

Read more about pseudocodes at:

brainly.com/question/11623795

3 0
2 years ago
How do i win Mine Craft
Vlad [161]
Answer: defeat the dragon? I think
3 0
3 years ago
Read 2 more answers
How come the scroll bar on the PA emojis only appears sometimes? how do I make it appear?
astraxan [27]
Answer it your own self everybody can't always give u the answers
5 0
3 years ago
Your team at amazon is overseeing the design of a new high-efficiency data center at HQ2. A power grid need to be generated for
Alla [95]

Following are the python program to the given question:

from collections import defaultdict #import package

import heapq as h#import package

def primsMST(gr, st_v): # defining a method primsMST that takes two values in parameters  

   primalMST = defaultdict(set)#defining primalMST as a variable that calls defaultdict method  

   v = set([st_v])# defining a variable v that calls the set method and hold its value

   e_list = [(c, st_v, to)for to, c in gr[st_v].items()]#defining variable e_list that use loop to hold value in list

   h.heapify(e_list)# use package that holds heapify and holds its value

   while e_list:#defining while loop that checks e_list  

       c, s, e = h.heappop(e_list)#holding heapop method value in c,s,and e variable

       if e not in v:#defining if block checks e value is not in v

           v.add(e)# use add method to add value in v

           primalMST[s].add(e)#use primalMST as list that adds value in mwthod

   for nxt, c in gr[e].items():#defining for loop that uses nxt, and c variable that checks value in list

       if nxt not in v:#defining nxt variable that checks value is not in v

           h.heappush(e_list, (c, e, nxt))#add value into the heappush method

   return primalMST#return method value

connects=[['A','B',1],['B','C',4],['B','D',6],['D','E',5],['C','E',1]]#defining a list connects

my_gr=dict()#defining a variable my_gr that holds method dict() value  

for el in connects:#defining a for loop that uses el to count connects list value

   my_gr[el[0]]=dict()#use my_gr as list hold value in dict method

   my_gr[el[1]]=dict()#use my_gr as list hold value in dict method

for el in connects:#defining another for loop that uses el to count connects list

   my_gr[el[0]].update({el[1]:el[2]}) # use update method that update value in my_gr

   my_gr[el[1]].update({el[0]:el[2]})# use update method that update value in my_gr

x=dict(primsMST(my_gr, list(my_gr.keys())[0]))#defining x variable that calls dict method and  hold its value  

a=[]#defining an empty list

for k in x:#defining a for loop that uses k to hold dict method value

   for no in x[k]:#defining a loop that checks list value

       a.append([k,no,my_gr[k][no]])#use a that add value in list  

       print(a)#print list value.

Output:

Please find the attached file.

Program Explanation:

  • Import package.
  • defining a method primsMST that takes "gr and st_v" as parameters.
  • Inside the method, a primalMST as a variable is declared that calls "defaultdict" method.
  • Use the v variable that calls the set method and hold its value.
  • Defining "e_list" that uses the loop to hold value in lists, and define the heapify and holds its value.
  • In the next step, it defines a while loop checks e_list, and defines variable and hold value into the method and use another if to check value and return its value.
  • A list "connects" is declared that holds a value and defines a "my_gr" that holds "dict" method value and uses multiple for loop to print the calculated list value.

Learn more:

dictionary: brainly.in/question/14673591

List: brainly.in/question/25140412

7 0
2 years ago
Other questions:
  • Write the definition of a method named printPowerOfTwoStars that receives a non-negative integer n and prints a string consistin
    10·1 answer
  • The set of specific, sequential steps that describe exactly what a computer program must do to complete the work is called a(n _
    14·1 answer
  • What runs a network, steering information between computers and managing security and users?
    11·1 answer
  • Enzo formed a study group for an upcoming geography test. To start off each session, they go over past notes and look at maps. T
    14·1 answer
  • If you are viewing a webpage with customized or regenerated content, such as updated stock quotes, what type of webpage are you
    14·1 answer
  • Does functionality provided by the app play an important role in a decision to
    13·1 answer
  • Select the correct answer.
    6·1 answer
  • What do you call a set of programs?
    7·1 answer
  • The World Wide Web is full of unstructured data. Search engines like Google, Bing and Yahoo have been doing a good job of allowi
    6·1 answer
  • Pls help will give brainlest!!! The image shows a line graph. Which scientist is most likely to use this visual aid in a present
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!